RtPrintf

RtPrintf prints formatted output to the standard output stream or console window.

Syntax

INT RtPrintf(
    LPCSTR lpFormat [,argument, . . .]
);

Parameters

lpFormat

The format control (with optional arguments).

Return Value

The number of characters printed if the function succeeds, a negative value if an error occurs

Remarks

RtPrintf is similar to printf, but RtPrintf does not require the C runtime library and can work with any combination of run-time libraries. This function does not support floating point conversions in the RTSS environment.

RtPrintf formats and prints a series of characters and values to the standard output stream, stdout. If arguments follow the format string, the format string must contain specifications that determine the output format for the arguments.

The format argument consists of ordinary characters, escape sequences, and (if arguments follow format) format specifications. The ordinary characters and escape sequences are copied to stdout in order of their appearance.

Format specifications always begin with a percent sign (%) and are read left to right. When RtPrintf encounters the first format specification (if any), it converts the value of the first argument after format and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications.

Requirements

Minimum Supported Version RTX64 2013
Header Rtapi.h
Library RtApi.lib (Windows), Rtx_Rtss.lib (RTSS)

Example

RtPrintf("Line one\n\t\tLine two\n");

produces the output:

Line one
  Line two

Format Specification Fields (RtPrintf and RtWprintf)

A format specification, which consists of optional and required fields, has the following form:

%[flags] [width] .precision] [{h|l|L}]type

Each field of the format specification is a single character or number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign is followed by a character that has no meaning as a format field, the character is copied to stdout. For example, to print a percent-sign character, use %%.

Required format field: The type character, which appears after the optional format fields, is the only required format field. It determines whether the associated argument is interpreted as a character, a string, or a number, as shown in the table that follows.

In the RTSS environment, the following limitations apply:

NOTE: The types C and S, and the behavior of c and s with RtPrintf and RtWprintf are consistent with Microsoft extensions for printf and are not ANSI compatible.

Type
Character

Argument
Type

Output

c

int

For RtPrintf, specifies a single-byte character.

For RtWprintf, specifies a wide character.

C

int

For RtPrintf, specifies a wide character.

For RtWprintf, specifies a single-byte character.

d

int

Signed decimal integer.

i

int

Signed decimal integer.

u

int

Unsigned decimal integer.

x

int

Unsigned hexadecimal integer, using "abcdef."

X

int

Unsigned hexadecimal integer, using "ABCDEF."

e

double

Signed value in the form:

[ - ]d.dddd e [sign]ddd

where, d is a single decimal digit, ddd is one or more decimal digits, ddd is exactly three decimal digits, and the sign is + or -.

E

double

Same as the "e" specifier. See above.

f
(Not supported in RTSS)

double

Signed value in the form:

[ - ]dddd.dddd

where, dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.

s

string

For RtPrintf, specifies a single-byte character string.

For RtWprintf, specifies a wide character string.

Characters are printed up to the first null character or until the precision value is reached.

S

string

For RtPrintf, specifies a wide character string.

For RtWprintf, specifies a single-byte character string.

Characters are printed up to the first null character or until the precision value is reached.

Optional format fields: The optional fields, which appear before the type character, control other aspects of the formatting, as shown in the list that follows.

flags

Optional character(s) that control justification of output and print of signs, blanks, decimal points, and octal and hexadecimal prefixes. More than one flag can appear in a format specification.

width

Optional number that specifies the minimum number of characters.

precision

Optional number that specifies the maximum number of characters printed for all or part of the output field or the minimum number of digits printed for integer values.

H|l| L

Optional prefixes to type that specify the size of the argument.

See Also:

RtAtoi

RtWPrintf

RtWtoi